<?php
namespace app\index\controller;

use think\Db;
use think\Config; 
use think\Controller;
use app\index\model\Category as Cate;

class Category extends Base
{
    /**
     * 栏目分类列表
     * @return string 分类列表模板
     */
    public function index()
    {
      //加载模块配置:默认分页条数
      define("PAGINATE_NUM",config('THUMBNAIL_DEFAULT_PAGINATE_NUM'));
  
      //判断表单是否Get传值
      if(request()->isGet()){
        
        $id = input('id');
          
        //查询数据库分类文章数量
        $count = Db::name('article')->where('category',$id)->count();
        
        //栏目文章是否为空
        if($count){
          
            //查询数据库,根据ID升序排列
            $res = Db::name('article')->where('category',$id)->where('status',1)->order('id asc')->paginate(PAGINATE_NUM);  
            
            //模板参数变量赋值
            $this->assign('ARTICLES',$res);
            
            //查询分类信息
            $Conf = Db::name('category')->where('id',$id)->find();  
            
            //模板参数变量赋值
            $this->assign('CONF',$Conf);
            
            return $this->fetch();
        
        }else{
            var_dump($count); die;
        }
      }
    }  
}